import requests
import os

'''
1. 获取文件信息，主要是文件名
2. 下载文件
'''

headers = {
    'TM-Header-Token': 'afe00e9557f8409481fcf16735a5d0be',
}

# 定义要下载的文件的URL
base_path = '/k8sapps/tmp/'
url = "http://fs-service/file/upload?appId=esae-template&tenantId=default&fileId={0}"
payload = {}
headers = {
    'TM-Header-Token': 'ad5ce76f15934adaa6f08b8e515b3641',
}

count = 0
with open('./d.txt', 'r') as f:
    for i in f.readlines():
        count = count + 1
        print(count)
        file_id = i.strip()
        folder_path = base_path + file_id + '/'
        if not os.path.exists(folder_path):
            continue
        for filename in os.listdir(folder_path):
            file_path = os.path.join(folder_path, filename)
            print(file_path)
            if os.path.isfile(file_path):
                with open(file_path, "rb") as file:
                    files = {"file": (filename, file)}
                    url2 = url.format(file_id)
                    print(url2)
                    response = requests.request("POST", url2, headers=headers, data=payload, files=files)
                    print(response.text)
